<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>vue</title>
    <script src="./vue.js"></script>
    </style>
</head>

<body>
    <div id="root">
        <p>firstname:</p>
        <input type="text" v-model='firstname'><br>
        <p>lastname:</p><input type="text" v-model='lastname'><br>
        <p>昵称:</p>
        <span>{{fullname}}</span>
    </div>
    <script>
        Vue.config.productionTip = false
        const vm = new Vue({
            el: '#root',
            data: {
                firstname: 'chen',
                lastname: 'kun',
                fullname: 'chen-kun'
            },
            watch: {
                firstname(newvalue) {
                    this.fullname = newvalue + '-' + this.lastname
                },
                lastname(newvalue) {
                    this.fullname = this.firstname + '-' + newvalue
                }
            }
        })
    </script>
</body>

</html>